package com.ndp.fb.walle.websocket;

import org.slf4j.LoggerFactory;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

import java.util.Map;

/**
 * Created by hermen on 7/22/2015.
 */
public class HandshakeInterceptor extends HttpSessionHandshakeInterceptor {

    private final org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());
    @Override
    public boolean beforeHandshake(ServerHttpRequest request,
                                   ServerHttpResponse response, WebSocketHandler wsHandler,
                                   Map<String, Object> attributes) throws Exception {
        logger.info("Before Handshake");
        //存入userId 判断发送用户
//        User user = (User) ((ServletServerHttpRequest) request).getServletRequest().getSession().getAttribute("user");
//        attributes.put("userId",user.getTicket());
        return super.beforeHandshake(request, response, wsHandler, attributes);
    }

    @Override
    public void afterHandshake(ServerHttpRequest request,
                               ServerHttpResponse response, WebSocketHandler wsHandler,
                               Exception ex) {
        logger.info("After Handshake");
        super.afterHandshake(request, response, wsHandler, ex);
    }

}